"use strict";
const { Model } = require("sequelize");
const moment = require("moment");
moment.locale("zh-cn");
module.exports = (sequelize, DataTypes) => {
  class SizeRule extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      models.SizeRule.belongsTo(models.User, {
        as: "user",
      });
      // define association here
    }
  }
  SizeRule.init(
    {
      long: DataTypes.INTEGER,
      wide: DataTypes.INTEGER,
      height: DataTypes.INTEGER,
      presetsNum: DataTypes.STRING,
      layerNum: DataTypes.STRING,
      palletizingNum: DataTypes.STRING,
      grippingDirection: DataTypes.STRING,
      leftAndRightFaultToleranceNum: DataTypes.STRING,
      faultToleranceBeforeAndAfterNum: DataTypes.STRING,
      userId: DataTypes.INTEGER,
      userName: DataTypes.STRING,
      beUsed: DataTypes.STRING,
      deletedAt: DataTypes.DATE,
      createdAt: {
        type: DataTypes.DATE,
        get() {
          return moment(this.getDataValue("createdAt")).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        },
      },
      updatedAt: {
        type: DataTypes.DATE,
        get() {
          return moment(this.getDataValue("updatedAt")).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        },
      },
    },
    {
      sequelize,
      paranoid: true,
      modelName: "SizeRule",
    }
  );
  return SizeRule;
};
